package controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import model.Book;
import model.MySql;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by yvdedu.com on 2016/9/27.
 */
@WebServlet(urlPatterns = "/get_hotbook")
public class get_hotbook extends HttpServlet{
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf-8");
        req.setCharacterEncoding("utf-8");
        MySql mySql=new MySql();
        List<Book> book=mySql.getBookByClick();
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(book);
        resp.getWriter().print(json);
    }
}
